package com.tjsinfo.tjsoa.baobiao.action;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.jfree.data.time.Month;
import org.json.JSONArray;
import org.json.JSONObject;

import com.tjsinfo.tjsoa.baobiao.bo.IHqBBSetManage;
import com.tjsinfo.tjsoa.baobiao.bo.IHqBBYhManage;
import com.tjsinfo.tjsoa.baobiao.bo.IHqJshtjbManage;
import com.tjsinfo.tjsoa.baobiao.vo.THqBBYh;
import com.tjsinfo.tjsoa.baobiao.vo.THqJshbfkhtjb;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.meetingroom.action.newArrangementsAction;
import com.tjsinfo.tjsoa.system.vo.User; 

public class JshtjbManageAction extends DispatchAction {
	
	private IHqBBYhManage hqBBYhManage;
    private IHqJshtjbManage hqJshtjbManage;
	private IHqBBSetManage hqBBSetManage;

	public IHqBBYhManage getHqBBYhManage() {
		return hqBBYhManage;
	}

	public void setHqBBYhManage(IHqBBYhManage hqBBYhManage) {
		this.hqBBYhManage = hqBBYhManage;
	}
	
	public IHqJshtjbManage getHqJshtjbManage() {
		return hqJshtjbManage;
	}

	public void setHqJshtjbManage(IHqJshtjbManage hqJshtjbManage) {
		this.hqJshtjbManage = hqJshtjbManage;
	}

	public IHqBBSetManage getHqBBSetManage() {
		return hqBBSetManage;
	}

	public void setHqBBSetManage(IHqBBSetManage hqBBSetManage) {
		this.hqBBSetManage = hqBBSetManage;
	}
	
	/**
		 * 准备进入上报统计表界面
		 * @param mapping
		 * @param form
		 * @param request
		 * @param response
		 * @return
		 * @throws Exception
		 */
	public ActionForward getTjb(ActionMapping mapping, ActionForm form,
					HttpServletRequest request, HttpServletResponse response)throws Exception {
				
			    String yueString = request.getParameter("yue");
			    if ("".equals(yueString)|| yueString==null){
			    	yueString =getJiduNow();
			    }
		    	User sessionUser = ToolKit.getSessionUser(request);
		    	String usernameString = "";
		    	if (null==sessionUser){
		    		usernameString = request.getParameter("user");
		    		if ("".equals(usernameString)|| null==usernameString){
		    			return mapping.findForward("failed");
		    		}else{
		    			usernameString = URLDecoder.decode(usernameString,"utf-8");
		    			User tempUser = new User();
		    			tempUser.setUsername(usernameString);
		    			request.getSession().setAttribute("user", tempUser);
		    		}
		    	}else{
		    		usernameString = sessionUser.getUsername();
		    	}
		    	List<THqBBYh> BBYhList = hqBBYhManage.findbyUser(usernameString,1);
		    	if (BBYhList.size()<1){    //如果当前用户不在计生用户列表中
		    		return mapping.findForward("failed");
		    	}
		    	Integer	yhidInteger = BBYhList.get(0).getId();
		    	String yhdwmchString = BBYhList.get(0).getDwmch();
		    
		        List<THqJshbfkhtjb> tjbList1 = hqJshtjbManage.findByYueYh(yueString , yhidInteger,"1");
			    List<THqJshbfkhtjb> tjbList2 = hqJshtjbManage.findByYueYh(yueString , yhidInteger,"2");
			    String typeString ="";
			    if (tjbList1.size()<1 || tjbList2.size()<1){
			    	THqJshbfkhtjb tjbtemp1 = new THqJshbfkhtjb(yhidInteger,yhdwmchString,yueString,"1");
			    	THqJshbfkhtjb tjbtemp2 = new THqJshbfkhtjb(yhidInteger,yhdwmchString,yueString,"2");
			        typeString ="add";
			        request.setAttribute("jshtjb1", tjbtemp1);
			        request.setAttribute("jshtjb2", tjbtemp2);
			        request.setAttribute("riqi", ToolKit.FormatDate(new Date()));
			    }else{
			    	request.setAttribute("jshtjb1", tjbList1.get(0));
			    	request.setAttribute("jshtjb2", tjbList2.get(0));
			    	if ("0".equals(tjbList1.get(0).getState())){
			    		request.setAttribute("riqi", ToolKit.FormatDate(new Date()));  //临时保存未提交的报表，上报日期显示当前日期
			    	}else{
			    		request.setAttribute("riqi", tjbList1.get(0).getRq());  //已提交过的报表，上报日期从记录中获取
			    	}
			    }
			    request.setAttribute("username", usernameString);
			    request.setAttribute("type", typeString);
				return mapping.findForward("getTjb");
		    
		}		
		/**
			 *  保存或提交统计表
			 * @param mapping
			 * @param form
			 * @param request
			 * @param response
			 * @return
			 * @throws Exception
			 */
	public ActionForward saveTjb(ActionMapping mapping, ActionForm form,
						HttpServletRequest request, HttpServletResponse response)throws Exception {
			String czyString= request.getParameter("username");
			String yueString= request.getParameter("yue");
			String riqiString = request.getParameter("riqi");
			String stateString = request.getParameter("state");
			String savetype = request.getParameter("type");
			
		    THqJshbfkhtjb jshtjb1=new THqJshbfkhtjb();
		    jshtjb1.setYhid(Integer.valueOf(request.getParameter("yhid")));
		    jshtjb1.setDwmch(request.getParameter("dwmch"));
		    jshtjb1.setYue(yueString);
		    jshtjb1.setXbbm("1");
		    jshtjb1.setZhgzs(Integer.valueOf(request.getParameter("zhgzs_1")));
		    jshtjb1.setWhqn(Integer.valueOf(request.getParameter("whqn_1")));
		    jshtjb1.setWshynl(Integer.valueOf(request.getParameter("wshynl_1")));
		    jshtjb1.setJy(Integer.valueOf(request.getParameter("jy_1")));
		    jshtjb1.setFh(Integer.valueOf(request.getParameter("fh_1")));
		    jshtjb1.setYzh(Integer.valueOf(request.getParameter("yzh_1")));
		    jshtjb1.setYp(Integer.valueOf(request.getParameter("yp_1")));
		    jshtjb1.setKfy(Integer.valueOf(request.getParameter("kfy_1")));
		    jshtjb1.setGj(Integer.valueOf(request.getParameter("gj_1")));
		    jshtjb1.setYm(Integer.valueOf(request.getParameter("ym_1")));
		    jshtjb1.setQt(Integer.valueOf(request.getParameter("qt_1")));
		    jshtjb1.setBrqagyn(Integer.valueOf(request.getParameter("brqagyn_1")));
		    jshtjb1.setHy_yt(Integer.valueOf(request.getParameter("hy_yt_1")));
		    jshtjb1.setHy_et(Integer.valueOf(request.getParameter("hy_et_1")));
		    jshtjb1.setHy_jhw(Integer.valueOf(request.getParameter("hy_jhw_1")));
		    jshtjb1.setXh(Integer.valueOf(request.getParameter("xh_1")));
		    jshtjb1.setChsh_yt(Integer.valueOf(request.getParameter("chsh_yt_1")));
		    jshtjb1.setChsh_et(Integer.valueOf(request.getParameter("chsh_et_1")));
		    jshtjb1.setChsh_jhw(Integer.valueOf(request.getParameter("chsh_jhw_1")));
		    jshtjb1.setYtsh(Integer.valueOf(request.getParameter("ytsh_1")));
		    jshtjb1.setLzhsh(Integer.valueOf(request.getParameter("lzhsh_1")));
		    jshtjb1.setCjzbdy(Integer.valueOf(request.getParameter("cjzbdy_1")));
		    jshtjb1.setDxrglch(Integer.valueOf(request.getParameter("dxrglch_1")));
		    jshtjb1.setChxrglch(Integer.valueOf(request.getParameter("chxrglch_1")));
		    jshtjb1.setBzzsh(Integer.valueOf(request.getParameter("bzzsh_1")));
		    jshtjb1.setQybz(Integer.valueOf(request.getParameter("qybz_1")));
		    jshtjb1.setYpxrsh(Integer.valueOf(request.getParameter("ypxrsh_1")));
		    jshtjb1.setShjpxrsh(Integer.valueOf(request.getParameter("shjpxrsh_1")));
		    jshtjb1.setXhdj25(Integer.valueOf(request.getParameter("xhdj25_1")));
		    jshtjb1.setXhdj23(Integer.valueOf(request.getParameter("xhdj23_1")));
		    jshtjb1.setXhdj22(Integer.valueOf(request.getParameter("xhdj22_1")));
		    jshtjb1.setShyrsh(Integer.valueOf(request.getParameter("shyrsh_1")));
		    jshtjb1.setWyrsh(Integer.valueOf(request.getParameter("wyrsh_1")));
		    jshtjb1.setRq(riqiString);
		    jshtjb1.setCzy(czyString);
		    jshtjb1.setState(stateString);
		    jshtjb1.setIntime("0");
			
			THqJshbfkhtjb jshtjb2=new THqJshbfkhtjb();
		    jshtjb2.setYhid(Integer.valueOf(request.getParameter("yhid")));
		    jshtjb2.setDwmch(request.getParameter("dwmch"));
		    jshtjb2.setYue(yueString);
		    jshtjb2.setXbbm("2");
		    jshtjb2.setZhgzs(Integer.valueOf(request.getParameter("zhgzs_2")));
		    jshtjb2.setWhqn(Integer.valueOf(request.getParameter("whqn_2")));
		    jshtjb2.setWshynl(Integer.valueOf(request.getParameter("wshynl_2")));
		    jshtjb2.setJy(Integer.valueOf(request.getParameter("jy_2")));
		    jshtjb2.setFh(Integer.valueOf(request.getParameter("fh_2")));
		    jshtjb2.setYzh(Integer.valueOf(request.getParameter("yzh_2")));
		    jshtjb2.setYp(Integer.valueOf(request.getParameter("yp_2")));
		    jshtjb2.setKfy(Integer.valueOf(request.getParameter("kfy_2")));
		    jshtjb2.setGj(Integer.valueOf(request.getParameter("gj_2")));
		    jshtjb2.setYm(Integer.valueOf(request.getParameter("ym_2")));
		    jshtjb2.setQt(Integer.valueOf(request.getParameter("qt_2")));
		    jshtjb2.setBrqagyn(Integer.valueOf(request.getParameter("brqagyn_2")));
		    jshtjb2.setHy_yt(Integer.valueOf(request.getParameter("hy_yt_2")));
		    jshtjb2.setHy_et(Integer.valueOf(request.getParameter("hy_et_2")));
		    jshtjb2.setHy_jhw(Integer.valueOf(request.getParameter("hy_jhw_2")));
		    jshtjb2.setXh(Integer.valueOf(request.getParameter("xh_2")));
		    jshtjb2.setChsh_yt(Integer.valueOf(request.getParameter("chsh_yt_2")));
		    jshtjb2.setChsh_et(Integer.valueOf(request.getParameter("chsh_et_2")));
		    jshtjb2.setChsh_jhw(Integer.valueOf(request.getParameter("chsh_jhw_2")));
		    jshtjb2.setYtsh(Integer.valueOf(request.getParameter("ytsh_2")));
		    jshtjb2.setLzhsh(Integer.valueOf(request.getParameter("lzhsh_2")));
		    jshtjb2.setCjzbdy(Integer.valueOf(request.getParameter("cjzbdy_2")));
		    jshtjb2.setDxrglch(Integer.valueOf(request.getParameter("dxrglch_2")));
		    jshtjb2.setChxrglch(Integer.valueOf(request.getParameter("chxrglch_2")));
		    jshtjb2.setBzzsh(Integer.valueOf(request.getParameter("bzzsh_2")));
		    jshtjb2.setQybz(Integer.valueOf(request.getParameter("qybz_2")));
		    jshtjb2.setYpxrsh(Integer.valueOf(request.getParameter("ypxrsh_2")));
		    jshtjb2.setShjpxrsh(Integer.valueOf(request.getParameter("shjpxrsh_2")));
		    jshtjb2.setXhdj25(Integer.valueOf(request.getParameter("xhdj25_2")));
		    jshtjb2.setXhdj23(Integer.valueOf(request.getParameter("xhdj23_2")));
		    jshtjb2.setXhdj22(Integer.valueOf(request.getParameter("xhdj22_2")));
		    jshtjb2.setShyrsh(Integer.valueOf(request.getParameter("shyrsh_2")));
		    jshtjb2.setWyrsh(Integer.valueOf(request.getParameter("wyrsh_2")));
		    jshtjb2.setRq(riqiString);
		    jshtjb2.setCzy(czyString);
		    jshtjb2.setState(stateString);
		    jshtjb2.setIntime("0");
			
			if ("1".equals(stateString)){
				if(isIntime(riqiString,yueString)){
					jshtjb1.setIntime("1");
					jshtjb2.setIntime("1");
				}
			}

			if("add".equals(savetype)){
				hqJshtjbManage.addBaobiao(jshtjb1, jshtjb2);
			}else {
				jshtjb1.setId(Integer.valueOf(request.getParameter("id1")));
				jshtjb2.setId(Integer.valueOf(request.getParameter("id2")));
				hqJshtjbManage.updateBaobiao(jshtjb1, jshtjb2);
			}
			request.setAttribute("linkurl", "tjsinfo/tjsoa/baobiao/JshTjbManage.do?method=getTjb");
			request.setAttribute("message", "system.save.message");
			return mapping.findForward("success");
	}

	/**
	 * 判断是否在截止日期前提交
	 * @param riqiString
	 * @param yueString
	 * @return
	 */
	private boolean isIntime(String riqiString, String yueString) {
			// TODO Auto-generated method stub
		
		    String deadline = hqBBSetManage.getDeadline("1");
		    String year = yueString.substring(0,4);
		    String jidu = yueString.substring(5).trim();
		    Integer month = (Integer.valueOf(jidu)-1)*3+Integer.valueOf(deadline.substring(0,1));
		    String dayString = deadline.substring(2);
		    String deadlineString = year+"-" + buling(String.valueOf(month)) + "-" + buling(dayString);
		    Date deadlineDate = ToolKit.FormatDate(deadlineString);
		    Date riqiDate = ToolKit.FormatDate(riqiString);
			return (riqiDate.getTime()<deadlineDate.getTime());
		}
	
/**
 * 单日或单月前面补零
 * @param str
 * @return
 */
	private String buling(String str) {
		// TODO Auto-generated method stub
		if (str.length()==1){
			str = "0"+str;
		}
		return str;
	}

	/**
	 * 提供上报页面季度下拉框的内容
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward getJiduList(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)throws Exception {
			
			
		Integer yhid = Integer.valueOf(request.getParameter("yhid"));
//		User sessionUser = ToolKit.getSessionUser(request);
//		List<THqBBYh>  BBYh = hqBBYhManage.findbyUser(sessionUser.getUsername());
		List<THqJshbfkhtjb> tjbList = hqJshtjbManage.findByYh(yhid);
		Map<String,String> map = new HashMap();
	 	JSONArray array	 = new JSONArray();
	 //	map.put("2012-3","0");
		for(THqJshbfkhtjb tjb:tjbList){
		    map.put(tjb.getYue().trim(),"0");	//将已存在的统计表季度放入map用于比对
	    	}
		List<String> yearJidulist = getYearJiduList(); //获取下拉框中的所有季度
    		for(String yearJidu:yearJidulist ){
			Object tempobj = map.get(yearJidu);
			JSONObject obj = new JSONObject();
			obj.put("yue",yearJidu);
			if (tempobj==null){   
				//该统计表不存在
				obj.put("exist","*");
			}else{
				//统计表已存在
				obj.put("exist","");
			}
			array.put(obj);
		}		

		
	 	response.getWriter().print(array);
		return null;
	}	
	
	/**
	 * 准备显示上报情况统计  
	 * @param mapping
	 * @param form
	 * @param requejst
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward toGetTjList(ActionMapping mapping, ActionForm form,
					HttpServletRequest request, HttpServletResponse response)throws Exception {
		
	    String yueString = request.getParameter("yue");
	    if ("".equals(yueString)|| yueString==null){
	    	yueString =getJiduNow();
	    }
		request.setAttribute("yue", yueString);
		return mapping.findForward("GetTJList");		
	}
				
	/**
	 * 显示上报情况统计 
	 * @param mapping
	 * @param form
	 * @param requejst
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward getTjList(ActionMapping mapping, ActionForm form,
					HttpServletRequest request, HttpServletResponse response)throws Exception {
				
		String yueString = request.getParameter("yue");
	    	if ("".equals(yueString)|| yueString==null){
		    	yueString =getJiduNow();
		    }
	    List<THqJshbfkhtjb> tjbList = hqJshtjbManage.findByJIdu(yueString);
		Map<String,String> map = new HashMap();
		JSONArray array	 = new JSONArray();
		for(THqJshbfkhtjb tjbtemp:tjbList){
			map.put(String.valueOf(tjbtemp.getYhid()),"0");
		}
		List<THqBBYh> yhList = hqBBYhManage.findAllenable(1);
		for(THqBBYh yhtemp:yhList){
			Object objtemp = map.get(String.valueOf(yhtemp.getId()));
			JSONObject obj = new JSONObject();
			obj.put("dwmch", yhtemp.getDwmch());
			obj.put("yue", yueString);
			obj.put("yhid", yhtemp.getId());
			if (objtemp==null){
				obj.put("exist", "0");
			}else{
				obj.put("exist", "1");
			}
			array.put(obj);
		}
	 	response.getWriter().print(array);
		return null;
	}
	
	/**
	 * 查询上报统计选择季度下拉框数据
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward getTjJiduList(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)throws Exception {
		
			JSONArray array = new JSONArray();
			List<Map<String, String>> tempList = hqJshtjbManage.getTjJidu();
			JSONObject obj = new JSONObject();
			obj.put("yue",getJiduNow());
			array.put(obj);
			for (Map<String, String> map : tempList) {
				JSONObject json = new JSONObject();
				json.put("yue", map.get("yue").trim());
				array.put(json);
			}
		    response.getWriter().print(array);
			return null;
		}
	
	/**
	 * 查看报表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward viewshangbao(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)throws Exception {
		
	    String yueString = request.getParameter("yue");
	    Integer yhid = Integer.valueOf(request.getParameter("yhid"));
        List<THqJshbfkhtjb> tjbList1 = hqJshtjbManage.findByYueYh(yueString , yhid,"1","1");
	    List<THqJshbfkhtjb> tjbList2 = hqJshtjbManage.findByYueYh(yueString , yhid,"2","1");
	    request.setAttribute("jshtjb1", tjbList1.get(0));
	    request.setAttribute("jshtjb2", tjbList2.get(0));
	    request.setAttribute("type", "single");
	    request.setAttribute("riqi", tjbList1.get(0).getRq());
		return mapping.findForward("viewshangbao");
		}	

	/**
	 * 退回统计表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward sendBackTjb(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)throws Exception {
		
	    Integer tjbid1=Integer.valueOf(request.getParameter("id1"));
	    Integer tjbid2=Integer.valueOf(request.getParameter("id2"));
		THqJshbfkhtjb tjbtemp1 = hqJshtjbManage.findById(tjbid1);
		THqJshbfkhtjb tjbtemp2 = hqJshtjbManage.findById(tjbid2);
		tjbtemp1.setState("2");
		tjbtemp2.setState("2");
		hqJshtjbManage.updateBaobiao(tjbtemp1, tjbtemp2);
		request.setAttribute("linkurl", "tjsinfo/tjsoa/baobiao/JshTjbManage.do?method=toGetTjList");
		request.setAttribute("message", "system.save.message");
		return mapping.findForward("success");
		}	
	/**
	 * 汇总统计表
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward collectTjb(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)throws Exception {
		
	    String yueString = request.getParameter("yue");
		THqJshbfkhtjb tjbtemp1 = hqJshtjbManage.collectByYue(yueString,"1");
		THqJshbfkhtjb tjbtemp2 = hqJshtjbManage.collectByYue(yueString,"2");
	    request.setAttribute("jshtjb1", tjbtemp1);
	    request.setAttribute("jshtjb2", tjbtemp2);
	    request.setAttribute("type", "collect");
		request.setAttribute("riqi", "");
		return mapping.findForward("viewshangbao");
		}	
	
	/**
	 * 计算当前日期所在季度
	 */
	public String getJiduNow(){
		
		Calendar cal = Calendar.getInstance();
 	    Integer jiduInteger = (cal.get(Calendar.MONTH)-1)/3+1 ;
 	    String yueString = cal.get(Calendar.YEAR)+"-"+jiduInteger;
		return yueString.trim();
	}

	/**
	 * 获取季度下拉列表
	 */
	public List<String> getYearJiduList(){
		Calendar cal = Calendar.getInstance();
 		Integer jiduInteger = (cal.get(Calendar.MONTH)-1)/3+1 ;
		Integer yearEnd = cal.get(Calendar.YEAR);
		ArrayList yearJiduList = new ArrayList();
		for (int j=jiduInteger;j>=1;j--){
			yearJiduList.add(yearEnd+"-"+j);
		}
		for (int i=yearEnd-1;i>yearEnd-3;i--){
			for(int j=4;j>=1;j--){
				yearJiduList.add(i+"-"+j);
			}
		}
		return yearJiduList;	
	}

	/**
	 * 获取截止日期
	 */	
		public ActionForward getDeadline(ActionMapping mapping, ActionForm form,
				HttpServletRequest request, HttpServletResponse response)throws Exception {
			   
			 String deadlineString = hqBBSetManage.getDeadline("1");
			 JSONObject json = new JSONObject();
			 json.put("month", deadlineString.substring(0,1));
			 json.put("day", deadlineString.substring(2));
			 response.getWriter().print(json);
			return null;
		}

	/**
	 * 设置截止日期
	 */	
			public ActionForward setDeadline(ActionMapping mapping, ActionForm form,
					HttpServletRequest request, HttpServletResponse response)throws Exception {
				String deadlineString = request.getParameter("deadline");
				JSONObject json = new JSONObject();
				json.put("success", hqBBSetManage.setDeadline(deadlineString,"1"));
				response.getWriter().print(json);
				return null;
			}	
			
	/**
	 * 统计及时率
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	public ActionForward count(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)throws Exception {
				
			    String yearString = request.getParameter("year");
			    String beginmonth = request.getParameter("beginmonth");
			    String endmonth = request.getParameter("endmonth");
			    Integer sumInteger = 0;
			    List<Map<String, String>> tempList = new ArrayList<Map<String,String>>();
			    if (yearString==null){
			    	if (beginmonth.compareTo(endmonth)>0){
			    		String tString=beginmonth;
			    		beginmonth=endmonth;
			    		endmonth=tString;
			    	}
			    	tempList = hqJshtjbManage.countIntime(beginmonth,endmonth);
			    	sumInteger = sumbymonth(beginmonth, endmonth);
			    }else{
			    	tempList = hqJshtjbManage.countIntime(yearString);
			    	sumInteger = sumbyyear(yearString);
			    }
			    
			    Map<String,String> jslMap = new HashMap();
			    for (Map<String, String> tempMap: tempList){
		 	    	Float jsl=(Float.valueOf(tempMap.get("intimecount"))/sumInteger)*100;
			    	String jslString = String.valueOf((float)(Math.round(jsl*100))/100)+"%";  // 截取两位小数
			    	jslMap.put(tempMap.get("yhid"), jslString);
			    }
			    
			    List<THqBBYh> userList = hqBBYhManage.findAllenable(1);
		  
				JSONArray array	 = new JSONArray();
					for (THqBBYh user : userList){
						Object objtemp = jslMap.get(String.valueOf(user.getId()));
			 			JSONObject jsObject = new JSONObject();
			 			jsObject.put("dwmch", user.getDwmch());
			 			if (objtemp==null){
			 				jsObject.put("jsl", "0.0%");
			 			}else{
			 				jsObject.put("jsl", objtemp);
			 			}
			 			array.put(jsObject);
				}
			 	response.getWriter().print(array);
				return null;
				}		
			
			/**
			 * 计算按年统计时的总数
			 */
				public Integer sumbyyear(String yearString){
					Integer countInteger=1;
					String todayString  = ToolKit.FormatDate(new Date());
					if (yearString.equals(todayString.substring(0,4))){ //this year
						String jiduString = getJiduNow();
						Integer jiduInteger = Integer.valueOf(jiduString.substring(5));
						if(isIntime(todayString,jiduString)&& jiduInteger!=1){  //未到截止日期
							countInteger = jiduInteger-1;
						}else{																//已到截止日期
							countInteger = jiduInteger;
						}
					}else{
						countInteger=4; //other year
					}
					return countInteger;
						
				}
			/**
			* 计算时段统计时的总数
			*/
				public Integer sumbymonth(String beginmonth, String endmonth)throws Exception{
					
					Integer beginYear = Integer.valueOf(beginmonth.substring(0,4));
					Integer beginMonth = Integer.valueOf(beginmonth.substring(5));

					Integer endYear = Integer.valueOf(endmonth.substring(0,4));
					Integer endMonth = Integer.valueOf(endmonth.substring(5));
					
					Integer difMonth = (endYear-beginYear)*4+(endMonth-beginMonth)+1;
					return difMonth;
								
				}			
}

